//package com.wanxi.filter;
//
//import org.springframework.stereotype.Component;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletContext;
//import javax.servlet.ServletException;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
///**
// * @author 杨金乾
// */
//@WebFilter("/*")
//@Component
//public class MyFilter extends HttpFilter {
//    @Override
//    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
//
//        //我们只需要拦截接口地址以back开头的即可，其他都不需要拦截
//        // 怎么得到前端访问后台的地址呢？
//        String path = req.getServletPath();
//        ServletContext application = req.getServletContext();
//        String userName = req.getHeader("Authorization");
//        if (path.startsWith("/back/")){
//            //判断用户是否已经登录
//            Object expirtTime = application.getAttribute(userName);
//
//            if (expirtTime == null){
//                //标识没有登录，则跳转到登录页面
//                res.sendRedirect("/html/login.html");
//            }else {
//                long exTime = Long.parseLong(expirtTime.toString());
//                if(exTime < System.currentTimeMillis()) {
//                    res.sendRedirect("/html/login.html");
//                }
//                //已经登录后则直接放行
//                chain.doFilter(req,res);
//            }
//        }else {
//            //不需要判断登录也直接放行
//            chain.doFilter(req,res);
//        }
//    }
//}
